package com.bridgeintelligent.tag.webserver.schedule.service;

import com.alibaba.fastjson.JSON;
import com.bridgeintelligent.tag.webserver.schedule.api.IQualityService;
import com.bridgeintelligent.tag.webserver.schedule.api.ITaskLogService;
import com.bridgeintelligent.tag.webserver.schedule.api.entity.TaskLog;
import com.bridgeintelligent.tag.webserver.schedule.service.task.CustomerAmountUpdateTask;
import com.bridgeintelligent.tag.webserver.schedule.service.task.TagStopTask;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @description
 * @author: grp 2020-09-14 11:28
 **/
@RestController
@RequestMapping("/api/schedule")
@Validated
@AllArgsConstructor
public class ScheduleController {

    private IQualityService qualityService;
    private CustomerAmountUpdateTask task;
    private TagStopTask tagStopTask;
    private ITaskLogService taskLogService;


    @GetMapping("updateQuality/{date}")
    Object updateDimFreeQuality(@PathVariable @NotBlank String date){
        qualityService.update(date);
        return JSON.parse("{\"code\":0}");
    }

    @GetMapping("updateCustomersAmount")
    Object updateJob(){
        task.updateJob();
        return JSON.parse("{\"code\":0}");
    }

    @GetMapping("stopJob")
    Object stopJob(){
        tagStopTask.stopJob();
        return JSON.parse("{\"code\":0}");
    }

    @GetMapping("jobs/{type}")
    Object jobList(@PathVariable String type){
        List<TaskLog> taskLogs = taskLogService.top3(type);
        return taskLogs;
    }
}
